<template>
  <div>

    <el-card>
      <el-table :data="commitmentList" style="width: 100%" border  :row-class-name="tableRowClassName">
        <el-table-column type="expand">
          <template slot-scope="props">
            <el-form label-position="left" inline class="demo-table-expand">
              <el-form-item label="请求用户名称">
                <span>{{ props.row.askUsername }}</span>
              </el-form-item>
              <el-form-item label="奖励名称">
                <span>{{ props.row.shopName }}</span>
              </el-form-item>
              <el-form-item label="奖励介绍">
                <span>{{ props.row.shopIntroduce }}</span>
              </el-form-item>
              <el-form-item label="数量">
                <span>{{ props.row.amount }}</span>
              </el-form-item>
              <el-form-item label="兑现限时">
                <span>{{ props.row.timeout }} (小时)</span>
              </el-form-item>
              <el-form-item label="请求时间">
                <span>{{ props.row.createTime }}</span>
              </el-form-item>
              <el-form-item label="到期时间">
                <span>{{ props.row.expirationTime }}</span>
              </el-form-item>
            </el-form>
          </template>
        </el-table-column>
        <el-table-column type="index" label="#"></el-table-column>
        <el-table-column label="奖励名称" prop="shopName"></el-table-column>
        <el-table-column label="数量" prop="amount"></el-table-column>
        <el-table-column label="操作">
          <template slot-scope="pro">
            <el-button type="primary" @click="supervisorFulfillCommitment(pro.row.id)">确认履行</el-button>
          </template>
        </el-table-column>
      </el-table>

      <el-pagination
        @size-change="handleSizeChange"
        @current-change="handleCurrentChange"
        :current-page="queryInfo.pageNum"
        :page-sizes="[10, 20, 40]"
        :page-size="queryInfo.pageSize"
        layout="total, sizes, prev, pager, next, jumper"
        :total="total"
      ></el-pagination>
    </el-card>
  </div>
</template>
<style lang="less" scoped>
.el-table .warning-row {
  background-color: oldlace;
}
.demo-table-expand {
  font-size: 0;
}
.demo-table-expand label {
  width: 90px;
  color: #99a9bf;
}
.demo-table-expand .el-form-item {
  margin-right: 0;
  margin-bottom: 0;
  width: 50%;
}
</style>

<script>
import { getSupervisorCommitmentList } from "@/utils/SupervisorApi";
import { fulfillCommitment } from "@/utils/SupervisorApi";

export default {
  data() {
    return {
      queryInfo: {
        type: 0,
        query: "",
        // 当前页数
        pageNum: 1,
        // 每页显示多少数据
        pageSize: 10,
      },
      total: 0,
      commitmentList: [],
    };
  },
  created() {
    this.getCommitmentList();
  },
  methods: {
    tableRowClassName({ row, rowIndex }) {
      if (row.statusType == 2) {
        return "warning-row";
      }
        return "";
    },
    async supervisorFulfillCommitment(id) {
      const { data: res } = await fulfillCommitment({ id: id });
      this.getCommitmentList();

      if (res.meta.status !== 200) {
        return this.$message.error("提交确认请求失败");
      }
    },
    addDialogClosed() {
      this.$refs.addTaskFormRef.resetFields();
    },
    async getCommitmentList() {
      console.log("dasd");
      const { data: res } = await getSupervisorCommitmentList(this.queryInfo);
      if (res.meta.status !== 200) {
        return this.$message.error("获取奖励列表失败！");
      }

      this.commitmentList = res.data.list;
      this.total = res.data.total;
    },
    handleSizeChange(newSize) {
      console.log(newSize);
      this.queryInfo.pageSize = newSize;
      this.getTaskList();
    },
    // 监听 页码值 改变事件
    handleCurrentChange(newSize) {
      // console.log(newSize)
      this.queryInfo.pageNum = newSize;
      this.getTaskList();
    },
  },
};
</script>